import {
    lang
} from 'muka'
export default {
    data: function () {
        return {
            clientWidth: 0,
            clientHeight: 0
        }
    },
    created: function () {
        let prefix = 'current_'
        let update = 'update_'
        for (let i in this._data) {
            if (i.includes(prefix) || i.includes(update)) {
                let listen = i.includes(prefix) ? i.substring(prefix.length) : i.substring(update.length)
                this[i] = this[listen] || ''
                this.$watch(listen, (newVal, oldVal) => {
                    if (newVal !== oldVal) this[i] = this[listen]
                })
                if (listen === 'value') {
                    this.$watch(i, (newVal, oldVal) => {
                        newVal !== oldVal && this.$emit('input', newVal)
                    })
                }
            }
            if (i.includes(update)) {
                let listen = i.substring(update.length)
                this[i] = this[listen] || ''
                this.$watch(i, (newVal, oldVal) => {
                    newVal !== oldVal && this.$emit('update:' + listen, newVal)
                })
            }
        }
        // 监听滚动派发的视图事件
        this.$on('on-client-window', (x, y) => {
            this.clientWidth = x
            this.clientHeight = y
        })
    }
}
